package com.woniuxy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.system.demol.entity.*;
import com.woniuxy.system.demol.vo.RoleAllVo;
import com.woniuxy.system.demol.vo.SpeUserVo;
import com.woniuxy.system.demol.vo.UserVo;
import com.woniuxy.system.mapper.*;
import com.woniuxy.system.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author why
 * @since 2023-09-08
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Resource
    private UserRoleMapper userRoleMapper;
    @Resource
    private RoleMapper roleMapper;
    @Resource
    private SystemSectorMapper systemSectorMapper;

    @Resource
    private SystemUserUpdateMapper systemUserUpdateMapper;

    @Override
    public User findall(String account) {
        return userMapper.findAll(account);
    }

    @Override
    public Map<String, Object> findAll2(Integer offset, Integer pageSize) {
        List<User> pageList = userMapper.findAll2(offset, pageSize);
        for (int i = 0; i < pageList.size(); i++) {
            if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 1) {
                pageList.get(i).setDepartment("管理层");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 2) {
                pageList.get(i).setDepartment("销售部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 3) {
                pageList.get(i).setDepartment("财务部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 4) {
                pageList.get(i).setDepartment("采购部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 5) {
                pageList.get(i).setDepartment("仓库部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 6) {
                pageList.get(i).setDepartment("产品部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 7) {
                pageList.get(i).setDepartment("商务部门");
            }
            if (Integer.valueOf(pageList.get(i).getState()).intValue() == 1) {
                pageList.get(i).setStatus(false);
            } else if (Integer.valueOf(pageList.get(i).getState()).intValue() == 0) {
                pageList.get(i).setStatus(true);
            }


        }

        int totalCount = userMapper.pageListCount();
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);
        return result;
    }

    @Override
    public Integer findByToken(String token) {
        String name = userMapper.findByToken(token);
        Integer uid = userMapper.findByAccount(name);
        return uid;
    }

    @Override
    public int pageListCount() {
        return userMapper.pageListCount();
    }
   // @GlobalTransactional
    @Transactional
    @Override
    public Boolean updateUser(UserVo userVo) {

        //先将用户的基本信息记录
        User newUser = new User();
        newUser.setAid(userVo.getAid());
        Integer id1 = userVo.getId();

        //根据id查询用户信息
        SimpleDateFormat formatter = new SimpleDateFormat(" yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String format = formatter.format(date);
        User user = userMapper.findByUId(id1);
        SystemUserUpdate systemUserUpdate = new SystemUserUpdate().setId(user.getId()).setAccount(user.getAccount()).setPassword(user.getPassword())
                .setSid(user.getSid()).setPhone(user.getCellphone())
                .setAid(user.getAid()).setTime(format).setState((Integer.valueOf(user.getState()).intValue()));

        //将未修改的记录放在修改记录表中
        systemUserUpdateMapper.insert(systemUserUpdate);

        //修改表格信息
        //1获取该用户的id
        newUser.setId(userVo.getId());
        //2判断是否有字段
        if (userVo.getAccount() != "" || userVo.getAccount().length() != 0) {
            newUser.setAccount(userVo.getAccount());
        }
        if (userVo.getPassword() != "" || userVo.getPassword().length() != 0) {
            BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
            String encode = encoder.encode(userVo.getPassword());
            newUser.setPassword(encode);
        }
        if (userVo.getSid() != "" || userVo.getSid().length() != 0) {
            newUser.setSid(userVo.getSid());
        }
        if (userVo.getCellphone() != "" || userVo.getCellphone().length() != 0) {
            newUser.setCellphone(userVo.getCellphone());
        }
        //System.out.println(user);
        String sid = user.getSid();
        // System.out.println(userVo.getSid());
        String sid1 = userVo.getSid();

        //如果sid为空或者和以前的一样则直接修改
        if (Objects.isNull(userVo.getSid()) || sid.equals(sid1)) {
            //修改
            int insert1 = userMapper.updateById(newUser);
            if (insert1 == 1) {
                return true;
            }
        } else {

            //根据sid查询该部门的名字
            SystemSector systemSector = systemSectorMapper.selectById(sid1);
            String name = systemSector.getName();
            //根据该部门的名字去查找对应角色的id为多少
            Role role = roleMapper.selectByName(name);
            Integer id = role.getId();
            //先删除原本账号对应的角色信息
            int i = userRoleMapper.deleteByUserId(userVo.getId());

            UserRole userRole = new UserRole().setUid(userVo.getId()).setRid(id);
            int insert = userRoleMapper.insert(userRole);
            //修改其余所有信息
            int insert1 = userMapper.updateById(newUser);
            if (insert == 1 && insert1 == 1) {
                return true;
            }
        }
        return false;
    }
   // @GlobalTransactional
   @Transactional
    @Override
    public Boolean updateUser2(UserVo userVo) {

        //先将用户的基本信息记录
        User newUser = new User();
        newUser.setAid(userVo.getAid());
        Integer id1 = userVo.getId();

        //根据id查询用户信息
        SimpleDateFormat formatter = new SimpleDateFormat(" yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String format = formatter.format(date);
        User user = userMapper.findByUId(id1);
        SystemUserUpdate systemUserUpdate = new SystemUserUpdate().setId(user.getId()).setAccount(user.getAccount()).setPassword(user.getPassword())
                .setSid(user.getSid()).setPhone(user.getCellphone())
                .setAid(user.getAid()).setTime(format).setState((Integer.valueOf(user.getState()).intValue()));

        //将未修改的记录放在修改记录表中
        systemUserUpdateMapper.insert(systemUserUpdate);

        //修改表格信息
        //1获取该用户的id
        newUser.setId(userVo.getId());
        //2判断是否有字段
        if (userVo.getAccount() != "" || userVo.getAccount().length() != 0) {
            newUser.setAccount(userVo.getAccount());
        }
        if (userVo.getPassword() != "" || userVo.getPassword().length() != 0) {
            BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
            String encode = encoder.encode(userVo.getPassword());
            newUser.setPassword(encode);
        }
        if (userVo.getSid() != "" || userVo.getSid().length() != 0) {
            newUser.setSid(userVo.getSid());
        }
        if (userVo.getCellphone() != "" || userVo.getCellphone().length() != 0) {
            newUser.setCellphone(userVo.getCellphone());
        }
        //System.out.println(user);
        String sid = user.getSid();
        // System.out.println(userVo.getSid());
        String sid1 = userVo.getSid();

        //如果sid为空或者和以前的一样则直接修改
        if (userVo.getIdentity().equals("1") && userVo.getSid().equals(sid)) {
            //修改
            //根据sid查询该部门的名字
            SystemSector systemSector = systemSectorMapper.selectById(sid1);
            String name = systemSector.getName();
            //根据该部门的名字去查找对应角色的id为多少
            Role role = roleMapper.selectByName(name);
            Integer id = role.getId();
            //先删除原本账号对应的角色信息
            int i = userRoleMapper.deleteByUserId(userVo.getId());

            UserRole userRole = new UserRole().setUid(userVo.getId()).setRid(id);
            int insert = userRoleMapper.insert(userRole);
            //修改其余所有信息
            int insert1 = userMapper.updateById(newUser);
            if (insert == 1 && insert1 == 1) {
                return true;
            }
        } else if (Objects.isNull(userVo.getSid())) {
            //修改
            int insert1 = userMapper.updateById(newUser);
            if (insert1 == 1) {
                return true;
            }

        } else if (userVo.getIdentity().equals("2") && userVo.getSid().equals(sid)) {
            //这里代表着部门一致。但是账号的角色变成了该部门的领导
            //根据uid查询rid
            SystemSector systemSector = systemSectorMapper.selectById(sid1);
            String str = systemSector.getName();
            str = str.substring(0, str.length() - 1); // 剔除最后一个字符
            String name = str + "m";
            //根据用户的id修改用户的角色
            Role role = roleMapper.selectByName(name);
            Integer id = role.getId();
            //先删除原本账号对应的角色信息
            int i = userRoleMapper.deleteByUserId(userVo.getId());

            UserRole userRole = new UserRole().setUid(userVo.getId()).setRid(id);
            int insert = userRoleMapper.insert(userRole);
            //修改其余所有信息
            int insert1 = userMapper.updateById(newUser);
            if (insert == 1 && insert1 == 1) {
                return true;
            }
        } else if (!userVo.getSid().equals(sid) && userVo.getIdentity().equals("1")) {
            //如果不一致则要修改其对应的角色信息
            //根据uid查询rid
            SystemSector systemSector = systemSectorMapper.selectById(sid1);
            String name = systemSector.getName();
            //根据用户的id修改用户的角色
            Role role = roleMapper.selectByName(name);
            Integer id = role.getId();
            //先删除原本账号对应的角色信息
            int i = userRoleMapper.deleteByUserId(userVo.getId());

            UserRole userRole = new UserRole().setUid(userVo.getId()).setRid(id);
            int insert = userRoleMapper.insert(userRole);
            //修改其余所有信息
            int insert1 = userMapper.updateById(newUser);
            if (insert == 1 && insert1 == 1) {
                return true;
            }
        } else if (!userVo.getSid().equals(sid) && userVo.getIdentity().equals("2")) {
            //如果不一致则要修改其对应的角色信息
            //根据uid查询rid
            SystemSector systemSector = systemSectorMapper.selectById(sid1);
            String str = systemSector.getName();
            str = str.substring(0, str.length() - 1); // 剔除最后一个字符
            String name = str + "m";
            //根据用户的id修改用户的角色
            Role role = roleMapper.selectByName(name);
            Integer id = role.getId();
            //先删除原本账号对应的角色信息
            int i = userRoleMapper.deleteByUserId(userVo.getId());

            UserRole userRole = new UserRole().setUid(userVo.getId()).setRid(id);
            int insert = userRoleMapper.insert(userRole);
            //修改其余所有信息
            int insert1 = userMapper.updateById(newUser);
            if (insert == 1 && insert1 == 1) {
                return true;
            }


        } else if (userVo.getIdentity().equals("3")) {
            //先删除原本账号对应的角色信息
            int i = userRoleMapper.deleteByUserId(userVo.getId());

            UserRole userRole = new UserRole().setUid(userVo.getId()).setRid(1);
            int insert = userRoleMapper.insert(userRole);
            //修改其余所有信息
            newUser.setSid("1");
            int insert1 = userMapper.updateById(newUser);
            if (insert == 1 && insert1 == 1) {
                return true;
            }


        }


        return false;
    }

    @Override
    public List<SystemUserUpdate> searchHistory(String account) {
        return userMapper.searchHistory(account);
    }

   // @GlobalTransactional
   @Transactional
    @Override
    public Boolean addUser(UserVo user) {
        System.out.println(user);
        //获取部门id
        String sid = user.getSid();
        int newSid = Integer.valueOf(sid).intValue();

        String identity = user.getIdentity();


        //设置rid记录rid
        Integer rid = 0;
        //判断是否为管理层新增的人员，如果是管理层，则逻辑不一致
        if (identity == "" || identity == null || identity.length() == 0 || Objects.isNull(identity)) {
            //账号的身份对应的是该部门编号的文员身份
            //找到对应的rid
            List<Role> list = userMapper.findBySid(newSid);


            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getName().endsWith("w")) {
                    rid = list.get(i).getId();
                }
            }
            if (rid == 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getName().endsWith("m")) {
                        rid = list.get(i).getId();
                    }
                }
            }
        } else if (identity.equals("1")) {
            System.out.println(1);
            //账号的身份对应的是该部门编号的文员身份
            //找到对应的rid
            List<Role> list = userMapper.findBySid(newSid);


            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getName().endsWith("w")) {
                    rid = list.get(i).getId();
                }
            }
            if (rid == 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getName().endsWith("m")) {
                        rid = list.get(i).getId();
                    }
                }
            }

        } else if (identity.equals("2")) {
            System.out.println(2);
            //账号的身份对应的是该部门编号的管理身份
            //找到对应的rid
            List<Role> list = userMapper.findBySid(newSid);


            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getName().endsWith("m")) {
                    rid = list.get(i).getId();
                }
            }
            if (rid == 0) {
                for (int i = 0; i < list.size(); i++) {
                    if (list.get(i).getName().endsWith("w")) {
                        rid = list.get(i).getId();
                    }
                }
            }


        } else if (identity.equals("3")) {
            //账号的身份对应的是该公司的管理员
            rid = 1;

        }
        //将数据插入表格
        UserRole userRole = new UserRole().setRid(rid).setUid(user.getId());
        int insert = userRoleMapper.insert(userRole);
        if (insert == 1) {
            return true;
        }


        return false;
    }

    @Override
    public Map<String, Object> findStateOpen(int offset, Integer pageSize) {
        List<User> pageList = userMapper.findAll3(offset, pageSize);
        for (int i = 0; i < pageList.size(); i++) {
            if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 1) {
                pageList.get(i).setDepartment("管理层");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 2) {
                pageList.get(i).setDepartment("销售部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 3) {
                pageList.get(i).setDepartment("财务部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 4) {
                pageList.get(i).setDepartment("采购部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 5) {
                pageList.get(i).setDepartment("仓库部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 6) {
                pageList.get(i).setDepartment("产品部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 7) {
                pageList.get(i).setDepartment("商务部门");
            }
            if (Integer.valueOf(pageList.get(i).getState()).intValue() == 1) {
                pageList.get(i).setStatus(false);
            } else if (Integer.valueOf(pageList.get(i).getState()).intValue() == 0) {
                pageList.get(i).setStatus(true);
            }


        }

        int totalCount = userMapper.pageListCount3();
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);
        return result;
    }

    @Override
    public Map<String, Object> findStateClose(int offset, Integer pageSize) {
        List<User> pageList = userMapper.findAll4(offset, pageSize);
        for (int i = 0; i < pageList.size(); i++) {
            if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 1) {
                pageList.get(i).setDepartment("管理层");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 2) {
                pageList.get(i).setDepartment("销售部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 3) {
                pageList.get(i).setDepartment("财务部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 4) {
                pageList.get(i).setDepartment("采购部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 5) {
                pageList.get(i).setDepartment("仓库部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 6) {
                pageList.get(i).setDepartment("产品部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 7) {
                pageList.get(i).setDepartment("商务部门");
            }
            if (Integer.valueOf(pageList.get(i).getState()).intValue() == 1) {
                pageList.get(i).setStatus(false);
            } else if (Integer.valueOf(pageList.get(i).getState()).intValue() == 0) {
                pageList.get(i).setStatus(true);
            }


        }

        int totalCount = userMapper.pageListCount4();
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);
        return result;
    }

    @Override
    public Map<String, Object> searchAll(Integer num, String input, int offset, Integer pageSize) {
        List<User> pageList = null;
        int totalCount = 0;
        if (num == 3) {
            totalCount = userMapper.pageListCount1(input, offset, pageSize);
            pageList = userMapper.searchAll(input, offset, pageSize);
        } else {
            pageList = userMapper.searchAll2(num, input, offset, pageSize);
            totalCount = userMapper.pageListCount2(num, input, offset, pageSize);
        }

        for (int i = 0; i < pageList.size(); i++) {
            if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 1) {
                pageList.get(i).setDepartment("管理层");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 2) {
                pageList.get(i).setDepartment("销售部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 3) {
                pageList.get(i).setDepartment("财务部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 4) {
                pageList.get(i).setDepartment("采购部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 5) {
                pageList.get(i).setDepartment("仓库部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 6) {
                pageList.get(i).setDepartment("产品部门");
            } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 7) {
                pageList.get(i).setDepartment("商务部门");
            }
            if (Integer.valueOf(pageList.get(i).getState()).intValue() == 1) {
                pageList.get(i).setStatus(false);
            } else if (Integer.valueOf(pageList.get(i).getState()).intValue() == 0) {
                pageList.get(i).setStatus(true);
            }


        }


        Map<String, Object> result = new HashMap<String, Object>();
        result.put("pageList", pageList);
        result.put("totalCount", totalCount);
        return result;
    }


    @Override
    public List<User> findAllAccount() {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.select("account");
        return userMapper.selectList(wrapper);
    }

    @Override
    public Map<String, Object> findSpeUser( int offset, Integer pageSize,String account) {
        //先根据account查询其对应的身份
        User all = userMapper.findAll(account);
        if (all.getSid().equals("1")) {
            List<SpeUserVo> pageList = userMapper.selectSpeUser(offset, pageSize);
            for (int i = 0; i < pageList.size(); i++) {
                if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 1) {
                    pageList.get(i).setDepartment("管理层");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 2) {
                    pageList.get(i).setDepartment("销售部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 3) {
                    pageList.get(i).setDepartment("财务部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 4) {
                    pageList.get(i).setDepartment("采购部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 5) {
                    pageList.get(i).setDepartment("仓库部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 6) {
                    pageList.get(i).setDepartment("产品部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 7) {
                    pageList.get(i).setDepartment("商务部门");
                }
            }
            Map<String, Object> result = new HashMap<String, Object>();
            int totalCount = userMapper.pageListCount3();
            result.put("pageList", pageList);
            result.put("totalCount", totalCount);
            return result;

        } else {
            String sid = all.getSid();
            List<SpeUserVo> pageList = userMapper.selectSpeUserBySid(offset, pageSize,sid);
            for (int i = 0; i < pageList.size(); i++) {
                if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 1) {
                    pageList.get(i).setDepartment("管理层");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 2) {
                    pageList.get(i).setDepartment("销售部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 3) {
                    pageList.get(i).setDepartment("财务部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 4) {
                    pageList.get(i).setDepartment("采购部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 5) {
                    pageList.get(i).setDepartment("仓库部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 6) {
                    pageList.get(i).setDepartment("产品部门");
                } else if (Integer.valueOf(pageList.get(i).getSid()).intValue() == 7) {
                    pageList.get(i).setDepartment("商务部门");
                }
            }
            Map<String, Object> result = new HashMap<String, Object>();
            int totalCount = userMapper.pageListCount7(sid);
            result.put("pageList", pageList);
            result.put("totalCount", totalCount);
            return result;
        }

    }
   // @GlobalTransactional
   @Transactional
    @Override
    public Boolean updateSpeUser(Integer rid, Integer speUid, Integer uid) {
        //rid是角色id speid是账号id uid是当前操作员的id
        //1根据id查询用户信息
        SimpleDateFormat formatter = new SimpleDateFormat(" yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        String format = formatter.format(date);
        User user = userMapper.findByUId(speUid);
        SystemUserUpdate systemUserUpdate = new SystemUserUpdate().setId(user.getId()).setAccount(user.getAccount()).setPassword(user.getPassword())
                .setSid(user.getSid()).setPhone(user.getCellphone())
                .setAid(uid).setTime(format).setState((Integer.valueOf(user.getState()).intValue()));

        //2将未修改的记录放在修改记录表中
        systemUserUpdateMapper.insert(systemUserUpdate);

        //3判断部门id是否一致
        //3.1获取原本的sid
        int sid = Integer.valueOf(user.getSid()).intValue();
        //3.2获取现在赋予的角色的sid
        RoleAllVo roleById = roleMapper.findRoleById(rid);
        Integer sid1 = roleById.getSid();
        //3.3判断
        if (sid==sid1){
            //两者相同则只需要修改user_role
            UserRole userRole = new UserRole().setRid(rid);
            int update = userRoleMapper.update(userRole, new UpdateWrapper<UserRole>().eq("uid", speUid));
            if (update==1){
                return true;
            }else {
                return false;
            }
        }else{
            //两者的不同
            //修改user_role表
            UserRole userRole = new UserRole().setRid(rid);
            int update = userRoleMapper.update(userRole, new UpdateWrapper<UserRole>().eq("uid", speUid));
            //修改账号的部门id即sid
            User user1 = new User().setId(speUid).setSid(roleById.getSid().toString());
            int i = userMapper.updateById(user1);
            if (update==i){
                return true;

            }else {
                return false;
            }

        }

    }

    @Override
    public Boolean fundPassword(String password,String account) {
       String a= userMapper.fundPassword(account);
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        boolean matches = passwordEncoder.matches(password, a);
       if (matches){
           return true;
       }
        return false;
    }
}
